package com.skyc.service.impl;

import com.skyc.dao.UserDao;
import com.skyc.dao.impl.UserDaoImpl;
import com.skyc.entity.User;
import com.skyc.service.UserService;

public class UserServiceImpl implements UserService {

	UserDao userdao = new UserDaoImpl();

	public User loginByname(String name, String pwd) {
		if ("".equals(name)||"".equals(pwd)||name==null||pwd==null|| name.length() < 2 || pwd.length() < 6) {
			return null;
		}
		return userdao.loginByname(name, pwd);
	}

	public User loginByphone(String phone, String pwd) {
		boolean flag=userdao.queryByPhone(phone);
		if(flag==true) {
			if ("".equals(phone)||"".equals(pwd)||phone==null||pwd==null||phone.length() < 11 || pwd.length() < 6) {
				return null;
			}
			return userdao.loginByphone(phone, pwd);
		}else {
			return null;
		}
		
	}

	@Override
	public User queryById(String name) {
		if (name != null && name.length() > 2) {
			return userdao.queryById(name);
		}
		return null;
	}

	@Override
	public User registerUser(User user) {
		boolean flag=userdao.queryByPhone(user.getUphone());
		if(flag==false) {
			if("".equals(user.getUphone())||"".equals(user.getUpwd())||user.getUphone()==null||user.getUpwd()==null||user.getUphone().length() < 11 || user.getUpwd().length() < 6) {
				return null;
			}
			return userdao.registerUser(user);
		}else {
			return null;
		}
		
	}

	@Override
	public User resetpwdByphone(User user) {
		boolean flag=userdao.queryByPhone(user.getUphone());
		if(flag==true) {
			if("".equals(user.getUphone())||"".equals(user.getUpwd())||user.getUphone()==null||user.getUpwd()==null||user.getUphone().length() < 11 || user.getUpwd().length() < 6) {
				return null;
			}
			return userdao.resetpwdByphone(user);
		}else {
			return null;
		}
		
	}

	@Override
	public User queryByphoneUser(String phone) {		
		return userdao.queryByphoneUser(phone);
	}

}
